package small.common.core.runnable;

public abstract class ExecuteRunnable implements Runnable{

    protected volatile Boolean shutdown = false;

    @Override
    public void run() {
        if (!shutdown) {
            try {
                executeBody();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                finalExecute();
            }
        }
    }

    protected abstract void executeBody();

    protected void finalExecute() {

    }

    public void shutdown() {
        shutdown = true;
    }

    public void start() {
        shutdown = false;
    }
}
